package com.ipmirror.common.base;

import com.ipmirror.text.MessageBundleLoader;
import com.ipmirror.utils.FacesUtils;
import com.ipmirror.utils.RegistryConsoleUtils;
import org.apache.log4j.Logger;

import javax.faces.context.FacesContext;
import java.util.Date;
import java.util.TimeZone;

/**
 * Created by denny
 * User: denny
 * Date: Oct 11, 2010
 * Time: 1:36:07 PM
 */
public abstract class AbstractBaseBean {
    private static final Logger log = Logger.getLogger(AbstractBaseBean.class);
    protected boolean visible;
    protected boolean showDataPager = true;
    protected boolean showRowControls = true;
    protected boolean showDetailPage = false;
    protected Date currenctTime=null;
    protected final static String DATA_TIME_PATTERN="hh:mm:ss dd/MM/yyyy";
    protected final static String DATE_PATTERN="dd/MM/yyyy";

    protected void init(){
//        log. info("init AbstractBaseBean");
        currenctTime= RegistryConsoleUtils.getCurrentDate();
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public boolean isShowDataPager() {
        return showDataPager;
    }

    public void setShowDataPager(boolean showDataPager) {
        this.showDataPager = showDataPager;
    }

    public boolean isShowRowControls() {
        return showRowControls;
    }

    public void setShowRowControls(boolean showRowControls) {
        this.showRowControls = showRowControls;
    }

    protected FacesContext getFacesContext() {
        return FacesContext.getCurrentInstance();
    }

    public TimeZone getTimeZone() {
        return java.util.TimeZone.getDefault();
    }

    public String getDateTimePattern(){
        return DATA_TIME_PATTERN;
    }

    public String getDatePattern(){
        return DATE_PATTERN;
    }

    protected void addErrorMessage(String clientId, String messageKey,
                                   Object... messageArgs) {
        FacesUtils.addErrorMessage(clientId, MessageBundleLoader.getMessage(
                messageKey, messageArgs));
    }

    protected void addErrorMessage(String messageKey, Object... messageArgs) {
        FacesUtils.addErrorMessage(null, MessageBundleLoader.getMessage(
                messageKey, messageArgs));
    }

    protected void addInfoMessage(String messageKey, Object... messageArgs) {
        FacesUtils.addInfoMessage(null, MessageBundleLoader.getMessage(
                messageKey, messageArgs));
    }

    protected void addInfoMessage(String clientId, String messageKey, Object... messageArgs) {
        FacesUtils.addInfoMessage(clientId, MessageBundleLoader.getMessage(
                messageKey, messageArgs));
    }

    public boolean isShowDetailPage() {
        return showDetailPage;
    }

    public void setShowDetailPage(boolean showDetailPage) {
        this.showDetailPage = showDetailPage;
    }

    public Date getCurrenctTime() {
        return currenctTime;
    }

    public void setCurrenctTime(Date currenctTime) {
        this.currenctTime = currenctTime;
    }
}
